package com.zyark.web.controller;

import com.zyark.domain.MemberInfo;
import com.zyark.model.ServerResponseModel;
import com.zyark.service.MemberInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Created by ron on 17-8-31.
 */
@Controller
@RequestMapping(value = "member")
public class MemberController {

    @Resource
    MemberInfoService memberInfoService;

    @RequestMapping(value = "list",method = RequestMethod.GET)
    @ResponseBody
    public ServerResponseModel<MemberInfo> getList(@RequestParam(value = "pageNumber",required = false)Integer pageNumber,
                                                   @RequestParam(value = "pageSize",required = false)Integer pageSize){
        if (pageNumber == null){
            pageNumber = 1;
        }
        if (pageSize == null){
            pageSize = 10;
        }
        return  memberInfoService.selectPageV2(pageNumber,pageSize);
    }

    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public Object saveMemberInfo(@RequestBody MemberInfo memberInfo){
        memberInfo.setCreateTime(new Date());
        return memberInfoService.saveSelective(memberInfo);
    }

    @RequestMapping(value = "{id}",method = RequestMethod.POST)
    @ResponseBody
    public Object updateMemberInfo(@RequestBody MemberInfo memberInfo){
        return memberInfoService.updateSelective(memberInfo);
    }

    @RequestMapping(value = "{id}",method = RequestMethod.DELETE)
    @ResponseBody
    public Object deleteMemberInfo(@PathVariable Integer id){
        return memberInfoService.delete(new MemberInfo(id));
    }
}
